﻿
$.ui.dialog.defaults.bgiframe = true;
$.ui.dialog.defaults.draggable = false;
$.ui.dialog.defaults.stack = false;
$.ui.dialog.defaults.resizable = false;

var X;
var Y;

jQuery(document).ready(function() {

    $().mousemove(function(e) {
        X = e.clientX + 15;
        Y = e.clientY + 15;
    });
    var dayOfWeek = (new Date()).getDay();
    if (dayOfWeek != 0) {
        $("table#classesTable tr").each(function() {
            this.cells[dayOfWeek].className = "currentDay";
        })
    }
})


function getSubjectDetails(e) {
    var URL = window.location + "/GetShortSubjectDetails/" + e.previousElementSibling.value;
    $.getJSON(URL, function(data) {

        var table = document.createElement('TABLE');
        var tbdy = document.createElement('TBODY');

        table.appendChild(tbdy);

        var trStart = document.createElement('TR');
        var tdStart = document.createElement('TD');

        tbdy.appendChild(trStart);
        trStart.appendChild(tdStart);
        tdStart.appendChild(document.createTextNode("Start:"));

        var tdStartValue = document.createElement('TD');
        trStart.appendChild(tdStartValue);
        tdStartValue.appendChild(document.createTextNode(data.ClassStartTime));

        var trEnd = document.createElement('TR');
        var tdEnd = document.createElement('TD');

        tbdy.appendChild(trEnd);
        trEnd.appendChild(tdEnd);
        tdEnd.appendChild(document.createTextNode("End:"));

        var tdEndValue = document.createElement('TD');
        trEnd.appendChild(tdEndValue);
        tdEndValue.appendChild(document.createTextNode(data.ClassEndTime));

        var trBuilding = document.createElement('TR');
        var tdBuilding = document.createElement('TD');

        tbdy.appendChild(trBuilding);
        trBuilding.appendChild(tdBuilding);
        tdBuilding.appendChild(document.createTextNode("Building:"));

        var tdBuildingValue = document.createElement('TD');
        trBuilding.appendChild(tdBuildingValue);
        tdBuildingValue.appendChild(document.createTextNode(data.Building));

        var trLetureRoom = document.createElement('TR');
        var tdLetureRoom = document.createElement('TD');

        tbdy.appendChild(trLetureRoom);
        trLetureRoom.appendChild(tdLetureRoom);
        tdLetureRoom.appendChild(document.createTextNode("Leture room:"));

        var tdLetureRoomValue = document.createElement('TD');
        trLetureRoom.appendChild(tdLetureRoomValue);
        tdLetureRoomValue.appendChild(document.createTextNode(data.LetureRoom));

        var trTeacher = document.createElement('TR');
        var tdTeacher = document.createElement('TD');

        tbdy.appendChild(trTeacher);
        trTeacher.appendChild(tdTeacher);
        tdTeacher.appendChild(document.createTextNode("Teacher:"));

        var tdTeacherValue = document.createElement('TD');
        trTeacher.appendChild(tdTeacherValue);
        tdTeacherValue.appendChild(document.createTextNode(data.Teacher));
        
        document.getElementById("dialog").removeChild(document.getElementById("dialog").firstChild);
        document.getElementById("dialog").appendChild(table);
    });
}

function ShowDetails(e) {
    getSubjectDetails(e);
    $('#dialog').dialog({ position: [X, Y], title: e.innerHTML });
};

function CloseDetails() {
    $('#dialog').dialog("destroy");
};

